<%[@ IncludeFile "Code/Util.vbs" ]%>
<%[@ IncludeFile "Code/Lang.vbs" ]%>
<%[@ IncludeFile "Code/TimelineInfo.vbs" ]%>
<%[
' The following prevents the page to be generated if the name is empty or the individual is excluded from the report.
' This is achieved simply by checking if the Href is empty
If (i.Href = "") Then
	Report.AbortPage
End If

Dim strName, g_strNameShort, strtTitle

strName = StrPlainName(i.Session("NameAlternative"))
g_strNameShort = i.Session("NameShort")
strTitle = Util.JavaScriptEncode(strName)

Report.TagBr = "<br />" & vbCRLF    ' For debugging, but it does not harm to re-define the <br /> tag



]%><?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv="Content-Language" content="@[WriteHtmlLang]@"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>@[Report.WriteText strName]@</title>
<meta name="description" content="@[WriteMetaDescription(i)]@" />
<meta name="keywords" content="@[WriteMetaKeywords(i)]@" />
<script src="scripts/script.js" type="text/javascript"></script>
<%[
	' create timeline data in JSON format.

	Dim nEvents, strLocale, strBuffer, collEvents, oEvent, strEvent, fTimeline, cchStart, oLinks, oTLInfo

	fTimeline = False
	If Session("Timelines") Then
		strLocale = GetLocale
		' force Locale to be English so that dates are in english. 
		SetLocale("en-gb")
		Set oLinks = Util.NewStringDictionary()
		Set oTLInfo = New TimelineInfo
		cchStart = Report.BufferLength

		oTLInfo.AddHeader True
		If CustomDate(i.Birth.Date).Year <> "" and CustomDate(i.Death.Date).Year <> "" Then
			oTLInfo.AddEvent i, i.Birth.Date, i.Death.Date, False, Dic("Lived"), ""
		Else
			oTLInfo.AddEvent i, i.Birth.Date, , False, Dic("Birth"), ""
			oTLInfo.AddEvent i, i.Death.Date ,i.Death.Date, False, Dic("Death"), ""
		End If
		oTLInfo.AddEvent "", i.Birth.Baptism.Date, , False, Util.FirstNonEmpty(i.Birth.CeremonyType, Dic("BirthCeremonyTypeDefault")), ""
		oTLInfo.AddEvent "", i.Death.Funerals.Date, , False, Dic("Funeral"), ""
		oTLInfo.AddEvent "", i.Death.Disposition.Date, , False, Dic.LookupEx("PhBD_", i.Death.Disposition.Type),""

		Set collEvents = i.Educations.ToGenoCollection
		For Each oEvent In collEvents
			oTLInfo.AddEvent oEvent, oEvent.DateStart, oEvent.DateEnd, False, StrPlainText(oEvent, Util.FirstNonEmpty(oEvent.Institution, oEvent.Place.Session("NameFull"), oEvent.Level)), ""
		Next

		Set collEvents = i.Occupations.ToGenoCollection
		For Each oEvent In collEvents
			oTLInfo.AddEvent oEvent, oEvent.DateStart, oEvent.DateEnd, False, StrPlainText(oEvent, Util.FirstNonEmpty(oEvent.Session("Title"), oEvent.Company, oEvent.Industry, oEvent.WorkType)), ""
		Next

		Set collEvents = i.Contacts.ToGenoCollection
		For Each oEvent In collEvents
			oTLInfo.AddEvent oEvent, oEvent.DateStart, oEvent.DateEnd, False, Util.IfElse(oEvent.Place.Name <> "", Util.FormatString(StrDicOrTag("Timeline_" & oEvent.Type.ID, CustomTag(oEvent, "NarrativeStyle")), oEvent.Place.Session("NameFull")),""), ""
		Next

		Set collEvents = i.Families.ToGenoCollection
		For Each oEvent In collEvents
			WriteFamilyEvents oTLInfo, oEvent, Replace(i.FindMate(oEvent).Session("NameFull"), Session("MarkerFirstName"), ""), False, True
		Next

		oTLInfo.AddTrailer True, ""

		If oTLInfo.Nodes >= Session("TimelineMinEventsIndividual") Then 
			fTimeline = True
		Else
			Report.BufferLength = cchStart
		End If

		setLocale(strLocale)
	End If
	' style sheet after timeline so can override style if required
	Report.WriteLn "<link rel=""stylesheet"" href=""style.css"" type=""text/css""/>"
	GoogleAnalytics
	Report.WriteLn "</head>"
	Report.WriteFormattedLn "<body  class='gno-detail' onload=""javascript:PageInit({}, '{}','');"">", Util.IfElse(Session("ForceFrames"), "true", "false"), strTitle
	Report.WriteLn "<div class='cage'><div class='floatright'> <!--cage stops the text on the individual page getting too wide which causes a horizontal scrollbar to appear-->"
	g_ichNotesStart = Report.BufferLength
	WriteHtmlButtonToggle("Notes")
	ichNotesEnd = Report.BufferLength
	g_ichReferencesStart = Report.BufferLength
	WriteHtmlButtonToggle("OtherDetails")
	ichReferencesEnd = Report.BufferLength
	Report.WriteLn "</div>"

Set oHyperlinkRings = Session("oHyperlinkRings")
Set oHyperlinkRingIndex = Session("oHyperlinkRingIndex")
Report.WriteFormatted "<h1>{}{}{}{}{}{}</h1>", StrHtmlImgGender(i), StrHtmlHighlightName(i.Session("NameAlternative")), StrHtmlImgFileGno(i), StrHtmlImgFileSvg(i), StrHtmlImgTimeline(i), StrHtmlImgMap(i)

'	put pictures in a 'div' floating right. If no pictures added then remove the 'div' 

Dim cchBufferStart	' Start of the write operations
Dim cchBufferBegin	' The begining of the picture data

cchBufferStart = Report.BufferLength

Report.WriteLn "<div class='floatright aligncenter widthpaddedlarge'>"

cchBufferBegin = Report.BufferLength

WriteHtmlPicturesLarge i, "right", "", ""
if Session("fShowPictureDetails") Then
	WriteHtmlDetailsPicture i, "", False
	WriteHtmlAnnotationPicture Dic("Individual"), i, "right", Session("cxPictureSizeLarge")
End If
If Report.BufferLength = cchBufferBegin Then		' no picture information written
	Report.BufferLength = cchBufferStart		' so remove the 'div' by stepping back the buffer
Else
	Report.WriteLn "</div>"				' close the 'div' with end tag
End If

WriteNarrativeIndividual i, false, Null
WriteHtmlAnnotation i, Dic("AnnotationGeneral"), i.Comment
WriteHtmlExtraNarrative i
WriteHtmlEducations(i)
WriteHtmlOccupations(i)
WriteHtmlOccupancies(i)
WriteHtmlRelationships i
If Session("PedigreeCharts") Then WriteHtmlPedigreeChart(i)
if fTimeline Then
]%>
	<div class='clearleft'><br /><ul class='xT'>
		<li class='xT3-o xT-h XT-clr clear' onclick='xTclk(event,"3")'>
		<a name='TimeLine'></a><h3 class='xT-i inline'>@[Report.WriteTextDic "TimelineHeadingIndividual"]@</h3><ul class='xT-h'><li>
		<div class='floatright'>
    <!--
			<img src="images/toggleduration.gif" onclick="javascript:timeLineToggleDuration();" alt="@[Report.WriteTextDic "AltTimeLineToggleDuration"]@" title="@[Report.WriteTextDic "AltTimeLineToggleDuration"]@">
			<img src="images/zoomin.gif" onclick="javascript:timeLineZoom(true);" alt="@[Report.WriteTextDic "AltTimeLineZoomIn"]@" title="@[Report.WriteTextDic "AltTimeLineZoomIn"]@">
			<img src="images/zoomout.gif" onclick="javascript:timeLineZoom(false);" alt="@[Report.WriteTextDic "AltTimeLineZoomOut"]@" title="@[Report.WriteTextDic "AltTimeLineZoomOut"]@">
     -->
		</div>
		<div id='timeline0' class="clear timeline" style="height: 50px; border: 1px solid #aaa;direction:ltr;" >
		</div>
		</li></ul></li></ul>
	</div>
<%[
End If

WriteHtmlAdditionalInformation(i)

If i.Families.Count > 0 And i.Families.Order.Count > 0 Then
	Set collFamilies = i.Families.Order.ToGenoCollection
Else
	Set collFamilies = i.Families.ToGenoCollection
End If
If Not Session("fHideFamilyDetails") Then
	If collFamilies.Count > 0 Then
		Report.WriteLn "<a name='Family'></a>"
		nFamily = 0
  		iFamilyLast = collFamilies.Count - 1
  		For iFamily = 0 To iFamilyLast
			If (iFamilyLast > 0) Then
				nFamily = iFamily + 1
			End If
			WriteHtmlFamily collFamilies(iFamily), nFamily, i
		Next
	End If
Else
  Report.Writeln "<div class='clear'></div>"
	For iFamily = 0 To collFamilies.Count - 1
		Set f = collFamilies(iFamily)
		Set spouse = i.FindMate(f)	' Find the other spouse
		strSpouseName = Util.IfElse(f.Parents.Count > 1, spouse.Session("NameFull"), "")
		If (strSpouseName = "") And Not Util.IsNothing(spouse) Then
			strSpouseName = StrDicMFU("_NoName", Util.FirstNonEmpty(spouse.Gender.ID,Util.IfElse(i.Gender.ID = "M", "F", "M")))
		End If
		strHyperlinkText = Dic.FormatPhrase("PhFamilyWith", i.Session("NamePossessive"), Dic.Ordinal(nFamily), strSpouseName, Dic("DetailLink"))
		Report.WriteFormatted "<h3>{}{}</h3>", StrHtmlImgFamily(f), Util.FormatHtmlHyperlink(f.Href, strHyperlinkText)
	Next
End If
If g_ichReferencesStart >= 0 Then
	' We have no place references, so remove the "Show All References | Hide All References"
	Report.BufferRemoveAt g_ichReferencesStart, ichReferencesEnd
End If
If (g_ichNotesStart >= 0) Then
	' We have no annotations, so remove the "collapse/expand all Notes" button
	Report.BufferRemoveAt g_ichNotesStart, ichNotesEnd
End If
Report.WriteLn "<span class='clear'></span>"
WriteHtmlAllFootnotes i.Sources, False
WriteHtmlFramesetSafeguardK i.Name, "GenoProReportIndividual", i


'===========================================================
' Subroutines to generate the page
'===========================================================
Sub WriteHtmlPedigreeChart(i)
	If  (i.Mother.Name<>"") Or (i.Father.Name<>"") Then
		g_ichReferencesStart = -1 ' indicate at least one collapse/expand non-notes section present

		Dim ChartMap
		Set ChartMap = Session("ChartMap")
		Dim Ancestors, fMore, depth
		fMore =False
		depth=0
		Set Ancestors = Util.NewObjectRepertory

		SetAncestor i, Ancestors, "", depth

		Dim e, r, s, c, obj, k
		s = Array(0)
		If depth > 0 Then
			Report.WriteLn "<div class='clearleft'><br /><ul class='xT'>"
			Report.WriteFormattedLn "    <li class='xT2-{} xT-h XT-clr clear{}' onclick='xTclk(event,""2"")'>", Util.IfElse(Session("fCollapseReferences"), "c", "o"), Util.IfElse(Session("fCollapseReferences"), "left", "")
			Report.WriteFormattedLn "<a name='PedigreeChart'></a><h3 class='xT-i inline'>{&t}</h3><ul class='xT-h'><li>", Dic("PedigreeChart")
			Report.WriteBr
			Report.WriteLn "<div class='nowrap' style='width:95%;direction:ltr;' >"
			For e = 0 to 62
				r = ChartMap.Entry(e).Object(0)
				k = r(r(0))
				If (Ancestors.KeyCounter(k)>0) Then
					Set obj = Ancestors.Object(k)
						If Not Util.IsNothing(obj) Then
							fMore = fMore Or PrintChartLine(r, obj, s)
							s = r
						End If
				End If
			Next
			Report.WriteLn "</div>"
			If fMore Then Report.Write "<a name='chartnote'></a><sup>*</sup>" & Dic("PedigreeChartFootnote")
			Report.WriteLn "</li></ul></li></ul></div>"
		End If
	End If
End Sub
Function PrintChartLine(r, i, s)
	Dim c, l, obj, strFill, strLink, fMore, gender, fPaddding, strName
	fMore = False
	fPadding = False
	gender = Right(r(r(0)),1)
	strName = Util.HtmlEncode(Util.IfElse(Session("OriginalNamesCharts"), i.TagValue(Session("TagNameFull")), Replace(i.Session("NameFull"), Session("MarkerFirstName"), "")))
	If gender = "i" Then
		gender = gender & i.Gender.ID
		For c = 1 to s(0)-1
			If s(c)="I" Or s(c)="T" Then
				Report.WriteFormatted "<img class='chart' src='images/line_I.gif' alt='' title=''/>"
				fPadding = True
			End If
		Next
		If fPadding Then Report.WriteBr
	End If
	For c = 1 to r(0)-1
		Report.WriteFormatted "<img class='chart' src='images/line_{}.gif' alt='' title=''/>", r(c)
	Next
	if i.Href <> "" Then
		strLink=Util.FormatString("<a href='{}' target='detail'>{}</a>", i.Href, Replace(strName," ","&nbsp;"))
	Else
	  strName = StrDicMFU("_NoName", i.Gender.ID)
		strLink=Util.HtmlEncode(strName)
	End If
	l=10 - Len(strName)

	If c=6 Then
		If i.Mother.Name <> "" Or i.Father.Name <> "" Then
			strLink = strLink & "<a href='#chartnote'><sup>* </sup></a>"
			fMore = True
		End If
	End If
	If l > 0 Then 
		For c= 1 To l
			strLink = strLink & "&nbsp;"
		Next
	End If
	Report.WriteFormattedLn "<div class='chartbox'><div class='chartbox charttext {0}'>{1}</div></div>{2}{3}"+Report.TagBr, _
					gender, strLink, "&nbsp;",_
					Replace(Util.HtmlEncode(Util.FormatPhrase(Dic("PedigreeChartDetails"), _
						Trim(CustomDate(i.Birth.Date).ToString(Dic("PedigreeChartDate"))), i.Birth.Place.Session("Locative"), _
						Trim(CustomDate(i.Death.Date).ToString(Dic("PedigreeChartDate"))), i.Death.Place.Session("Locative")))," ","&nbsp;")
	If fMore Then
		PrintChartLine = True
	Else
		PrintChartLine = False
	End If
End Function
Function SetAncestor(i, Ancestors, p, ByRef depth)
	Ancestors.Object(Util.FirstNonEmpty(p,"i")) = i
	If Len(p) < 5 Then
		If Not Util.IsNothing(i.Father) Then SetAncestor i.Father, Ancestors,p & "f", depth
		If Not Util.IsNothing(i.Mother) Then SetAncestor i.Mother, Ancestors,p & "m", depth 
	End If
	If Len(p) > depth Then depth = Len(p)
End Function
Sub WriteHtmlEducations(i)
		Dim strPrefix, e, p, collEducations, strTermination
	Set collEducations = i.Educations.ToGenoCollection
	If (collEducations.Count > 0) Then
		g_ichReferencesStart = -1 ' indicate at least one collapse/expand non-notes section present
		Report.WriteLn	"<div class='clearleft'><br /><ul class='xT'>"
		Report.WriteFormattedLn "    <li class='xT2-{} xT-h' onclick='xTclk(event,""2"")'>", Util.IfElse(Session("fCollapseReferences"), "c", "o")
		Report.WriteFormattedLn "<a name='Education'></a><h3 class='xT-i inline'>{&t}</h3><ul class='xT-h'><li>", Dic("HeaderEducation")
		strPrefix = g_strNameShort
		Set oRegExp = New RegExp
		oRegExp.Global=True
		oRegExp.Pattern="[\.\ \(\)\\\/,']"
		For Each e In collEducations 
			Report.WriteFormattedLn "<a name='{}'></a><div class='clearleft'>", e.ID
			If (e.Pictures.Count > 0) Then
				Report.WriteLn "<div class='floatleft aligncenter widthpaddedsmall'>"
				WriteHtmlPicturesSmall e, "left", True
				Report.WriteLn "</div>"
			End If
			Set p = e.Place

			If e.Termination.ID <> "" Then
				strTermination = StrDicMFU2("PhET_" & e.Termination.ID, i.Gender.ID, "=" & e.Termination, "2.0.1.?")
				If Instr(strTermination,"{") > 0 Then strTermination = Util.FormatPhrase(strTermination, i.Gender.ID)
			Else
				strTermination = ""
			End If
			Report.WritePhrase StrDicOrTag("PhEducation", CustomTag(e, "NarrativeStyle")), _
							strPrefix, _
							Util.IfElse(e.Institution <> p.Name, p.Session("HlinkLocative"), p.Session("Hlink")), _
							e.StudyType, _
							StrDateSpan(e.DateStart, Util.IfElse(e.Termination = "", e.DateEnd, Nothing)), _
				 			e.Duration, _
							Util.FirstNonEmpty(Dic.Peek("PhEL_" & oRegExp.Replace(e.Level,"")),Util.FormatPhrase(Dic("PhEL"),e.Level)), _
							StrFormatText(e, e.Program), _
							Util.FirstNonEmpty(Dic.Peek("PhEA_" & oRegExp.Replace(e.Achievement,"")), Util.FormatPhrase(Dic("PhEA"), StrFormatText(e, e.Achievement))), _
							e.Termination.ID = "StillAttending", _
							Util.IfElse(e.Institution <> p.Name, StrParseText(StrPlaceTranslate(e.Institution), True), ""), _
							PnP(i), _
							CustomDate(e.DateEnd).ToStringNarrative, _
							strTermination, _
							Dic.Peek("PrefixInstitution_" & CustomTag(e, "Institution.Prefix")), _
							Dic.Peek("PrefixProgram_" & CustomTag(e, "Program.Prefix"))
			WriteHtmlFootnoteRef(e.Source)
			WriteHtmlFootnoteRefs(e.Sources)
			WriteHtmlAdditionalInformation(e)
			WriteHtmlAnnotation e, Dic("AnnotationEducation"), e.Comment
			If Session("fShowPictureDetails") Then
				WriteHtmlDetailsPicture e, True, True
				WriteHtmlAnnotationPicture Dic("Education"), e, "", ""
			End If
			Report.WriteBr "</div>"
			strPrefix = PnP(i)
		Next
		Report.WriteLn "</div>"
		Report.WriteLn "</li></ul></li></ul></div>"
	End If
End Sub

Sub WriteHtmlOccupations(i)
	Set collOccupations = i.Occupations.ToGenoCollection
	If (collOccupations.Count > 0) Then
		g_ichReferencesStart = -1 ' indicate at least one collapse/expand non-notes section present
		Report.WriteLn	"<div class='clearleft'><br /><ul class='xT'>"
		Report.WriteFormattedLn "    <li class='xT2-{} xT-h' onclick='xTclk(event,""2"")'>", Util.IfElse(Session("fCollapseReferences"), "c", "o")
		Report.WriteFormattedLn "<a name='Occupation'></a><h3 class='xT-i inline'>{&t}</h3><ul class='xT-h'><li>", Dic("HeaderOccupation")
		Dim strRelative, strPnP, strGender, strName
		strGender = i.Gender.ID
		strRelative = i.Session("NamePossessive")
		strPnp = PnP(i)
		strName = i.Session("NameShort")
		For Each o In collOccupations
			Report.WriteFormattedLn "<a name='{}'></a><div class='clearleft'>", o.ID
			If (o.Pictures.Count > 0) Then
				Report.WriteLn "<div class='floatleft aligncenter widthpaddedsmall'>"
				WriteHtmlPicturesSmall o, "left", True
				Report.WriteLn "</div>"
			End If
			Report.WritePhrase StrDicOrTag("PhOccupation", CustomTag(o, "NarrativeStyle")), _
							StrDateSpan(o.DateStart, Util.IfElse(o.Termination.ID = "", o.DateEnd, nothing)), _
							o.Duration, _
							strRelative, _
							StrFormatText(o, StrParseText(o.Session("Title"), True)), _
							o.WorkType, o.Industry, _
							StrFormatText(o, StrParseText(o.Company, True)), _
							StrHtmlHyperlink(o.Place), _
							o.Termination.ID = "StillWorking", _
							strName, _
							Util.FirstNonEmpty(Dic.Peek("PrefixTitle_" & CustomTag(o, "Title.Prefix")), CustomTag(o, "Title.Prefix")), _
							Util.FirstNonEmpty(Dic.Peek("PrefixCompany_" & CustomTag(o, "Company.Prefix")), CustomTag(o, "Company.Prefix"))
			Report.WritePhrase StrDicMFU("PhJT_" & o.Termination.ID, i.Gender.ID), strPnP, CustomDate(o.DateEnd).ToStringNarrative, strGender
			WriteHtmlFootnoteRef(o.Source)
			WriteHtmlFootnoteRefs(o.Sources)
			WriteHtmlAdditionalInformation(o)
			WriteHtmlAnnotation o, Dic("AnnotationOccupation"), o.Comment
			If Session("fShowPictureDetails") Then
				WriteHtmlDetailsPicture o, True, True
				WriteHtmlAnnotationPicture Dic("Occupation"), o, "", ""
			End If
			strName = strPnP
			strRelative = PnR(i)
			Report.WriteLn "</div>"
		Next
		Report.WriteLn "</li></ul></li></ul></div>"
	End If
End Sub
'	If obj.Class = "Individual" Or obj.Class = "SocialEntity" Then ' List any Social or Emotional Relationships here
'		cchBufferStart = Report.BufferLength
'		Report.WriteLn "<br /><li class='xT2-o xT-h' onclick='xTclk(event,""2"")'>"
'		Report.WriteFormattedLn "<span class='xT-i subhead bold'>{&t}</span><ul class='xT-h'><li>", Dic("Relationships")
'		cchBufferNow = Report.BufferLength
'		WriteHtmlRelationships obj
'		If Report.BufferLength > cchBufferNow Then ' some relationships written
'			cchBufferBegin = -1	  ' indicate data present in Additional Information section
'			Report.WriteLn "</li></ul></li><div class='clearleft'></div>"
'		Else 
'			Report.BufferLength = cchBufferStart
'		End If
'	End If


Sub WriteMetaDescription(i)
	Dim b, c, s, cMateFemale, cChildFemale, o, strSpouse
	strSpouse = "_Spouse" 
	Set b = i.Birth	
	Report.WritePhraseDic "FmtMetaDescIndividual1", _
		StrPlainName(i.Session("NameFull")), Dic.LookupEx("Child_", i.Gender.ID), StrPlainName(i.Father.Session("NameFull")), StrPlainName(i.Mother.Session("NameFull")), CustomDate(b.Date).ToStringNarrative, b.Place.Session("Locative"), i.Gender.ID = "F", StrPlainName(i.Session("NameFullPossessive")), StrPlainName(i.Father.Session("NameFullPossessive")), StrPlainName(i.Mother.Session("NameFullPossessive"))
	
	Set s = i.Mates.ToGenoCollection
	cMateFemale = 0
	For Each o in s
		If o.Gender.ID = "F" Then cMateFemale = cMateFemale + 1
	Next
	If s.Count = cMateFemale Then
		If Dic.Peek(strSpouse & "_" & i.Gender.ID & "_F") <> "" Then strSpouse = strSpouse & "_" & i.Gender.ID & "_F"
	End If	
	Set c = i.Children.ToGenoCollection
	cChildFemale = 0
	For Each o in c
		If o.Gender.ID = "F" Then cChildFemale = cChildFemale + 1
	Next
	Report.WritePhraseDic "FmtMetaDescIndividual2", i.Session("NameShort"), ToHave(i, s), _
		Dic.PlurialCardinal(strSpouse, s.Count), s.ToString, _
		Dic.PlurialCardinal("Child", c.Count), c.ToString(Session("NameTags")(3)), _
		s.Count = cMateFemale, s.Count > 1, c.Count = cChildFemale, c.Count > 1
End Sub

Sub WriteMetaKeywords(i)
	Report.WritePhraseDic "FmtMetaKeyWordsIndividual", i.Session("FullName"), i.Session("NameLast"), i.Pictures.Count > 0, i.Session("NameFullPossessive")
End Sub

]%>
<br />
<span class='clear'></span></div> <!--close cage-->
</body>

</html>
